package com.idp.filter;


import org.springframework.util.StringUtils;

import javax.servlet.*;
import javax.servlet.annotation.WebFilter;
import java.io.IOException;

@WebFilter(urlPatterns = "/*", filterName = "authFilter")
public class AccessFilter implements Filter {

    @Override
    public void init(FilterConfig filterConfig) {
    }

    @Override
    public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain)
            throws IOException, ServletException {
        if (StringUtils.isEmpty(servletRequest.getParameter("ticket"))) {
            System.out.println("mock a redirection to authentication system");
            //Check if the user has been authenticated
            //If user has not logged in, redirect to identity provider authentication system
        }
        filterChain.doFilter(servletRequest, servletResponse);
    }

    @Override
    public void destroy() {
    }
}
